from common.base import *


# 打开浏览器
driver = webdriver.Chrome()
driver.maximize_window()
# 请求163
driver.get('https://mail.163.com')
# 准备cookie
cookies = [
    {
        'name': 'NTES_SESS',
        'value': 'yuH_uGt6aD_GkAKndtA_VWstgaxPQNLiQboJ.x3DNL2EgN.agb3pG9dTe1c2etcDbTGrkU4Myl6N5TkxMQSRe8o1UpjhL.lSTQWrtYxb5WsENOoCviXihFGK0IEiyspsra.B6X0hr3w5mmXbUyr_s1UdEAHQrVmLpIl.W1weW9tnyBQZyeGwg8wlt0OhHXzxAd58O_sVvt0V9'
    },
    {
        'name': 'Coremail',
        'value': '7fdb90539c6b0%SCZozcwZiUcvmlflpIZZCERnguTHJbmW%g1a109.mail.163.com'
    },
    {
        'name': 'MAIL_ENTRY_INFO',
        'value': '1|0|mail163|mail163_letter|221.234.129.46|caaeef2415a86fe726a64d5d64cfca05_v1|'
    },
    {
        'name': 'MAIL_ENTRY_CS',
        'value': '3eff2314c3949add1a545a0ebf93e89e'
    },
    {
        'name': 'cm_last_info',
        'value': 'dT15a2wyMDIwMTY4JTQwMTYzLmNvbSZkPWh0dHBzJTNBJTJGJTJGbWFpbC4xNjMuY29tJTJGanM2JTJGbWFpbi5qc3AlM0ZzaWQlM0RFQXRjbHFsaHB3Q0R2ckFkQ3FoaElnTWdpampjcVRybCZzPUVBdGNscWxocHdDRHZyQWRDcWhoSWdNZ2lqamNxVHJsJmg9aHR0cHMlM0ElMkYlMkZtYWlsLjE2My5jb20lMkZqczYlMkZtYWluLmpzcCUzRnNpZCUzREVBdGNscWxocHdDRHZyQWRDcWhoSWdNZ2lqamNxVHJsJnc9aHR0cHMlM0ElMkYlMkZtYWlsLjE2My5jb20mbD0tMSZ0PS0xJmFzPXRydWU='}
]

# 添加cookie
for i in cookies:
    driver.add_cookie(i)

# 刷新浏览器
sleep(2)
driver.refresh()
# 定位收件人, 输入信息
driver.find_element(By.CLASS_NAME, 'nui-editableAddr-ipt').send_keys('hello@hello.com')
# 定位主题,输入信息
driver.find_element(By.XPATH, '//input[contains(@id, "_subjectInput")]').send_keys('subject_test')
# 定位正文,输入信息
# 切换到frame
editor_frame = driver.find_element(By.CLASS_NAME, 'APP-editor-iframe')
driver.switch_to.frame(editor_frame)
body = driver.find_element(By.TAG_NAME, 'body')
body.send_keys('你好')
# js = 'document.body.innerHTML="content_text"'
# driver.execute_script(js)

# TODO 发送操作
# 定位发送, 点击
sleep(2)
driver.switch_to.parent_frame()
footer = driver.find_element(By.TAG_NAME, 'footer')
send_div = footer.find_element(By.TAG_NAME, 'div')
send_div.click()
# 关闭浏览器
sleep(5)
driver.quit()
